/*************************************************************************
	> File Name: acqdata.cpp
	> Author: xuwenlong
	> Mail: myxuan475@126.com 
	> Created Time: 2018年03月13日 星期二 15时15分52秒
 ************************************************************************/

#include <stdio.h>
#include <time.h>
#include <utils/custom.h>
#include "acqitem.h"

AcqItem::AcqItem()
{
    itemid = 0;
    data = OpValue::Null();
}

AcqItem::AcqItem(const OpValue &data_) {
    data = data_;
}

AcqItem &AcqItem::operator =(const OpValue &data_)
{
    data = data_;
    return *this;
}

void AcqItem::SetId(U16 id)
{
    itemid = id;
}

Json::Value AcqItem::ToJson()
{
    switch(data.type) {
    case TYPE_S8:
        return data.data.s8;
    case TYPE_U8:
        return data.data.u8;
    case TYPE_S16:
        return data.data.s16;
    case TYPE_U16:
        return data.data.u16;
    case TYPE_S32:
        return data.data.s32;
    case TYPE_U32:
        return data.data.u32;
    case TYPE_S64:
        return data.data.s64;
    case TYPE_U64:
        return data.data.u64;
    case TYPE_F32:
        return data.data.f32;
    case TYPE_F64:
        return data.data.f64;
    default:
        return data.data.f64;
    }
}

void AcqItem::SetName(const char *name_)
{
    strncpy(name,name_,64);
}

void AcqItem::SetName(const std::string &name_)
{
    SetName(name_.c_str());
}

const char *AcqItem::GetName() const
{
    return name;
}

U16 AcqItem::GetId() const
{
    return itemid;
}

OpValue *AcqItem::Value(OpValue *bf)
{
    if (!bf)
        return &data;
    return bf->Next();
}
